package com.example.websocket.OOP;

import com.example.websocket.excel.Goods;
import com.example.websocket.html.GoodsPO;

import java.util.*;

import static java.lang.System.*;

public class Shape {

    int j;

    void test() {
        int i = 5;
        out.println(++i + 2);
        System.out.println(i++ + 3);
        out.println(i);
        j = i;
        List<Integer> list = new ArrayList<>();
        list.add(4);
        list.add(5);
        out.println(list.get(1));
        list.set(1, 10);
        out.println(list.get(1));
        Collections.addAll(list, 1, 3, 6, 8);
    }

    class Inner {
        public void test() {
            out.println("test");
        }
        private class TestInner {
            public void test() {
                Inner.this.test();
            }
        }
    }

    public Inner testShape() {
        Shape shape = Shape.this;
        Shape.Inner inner = shape.new Inner();
        return inner;
    }

    public Shape() {
    }

    public Shape(int j) {
        this.j = j;
    }

    @Override
    protected void finalize() throws Throwable {
        out.println(j);
        out.println("finalizing....");
//        super.finalize();
    }

    public static void main(String[] args) {
        String t1 = "20200626135724";
        String t2 = "20200626135725";
        out.println(t2.compareTo(t1));
        Shape shape = new Shape(10);
        shape.test();
        new Shape(12);
        gc();
        while (true) {
            String a = "great";
            a = shape.cutString(a);
            String b = "rgeat";
            if (a.equals(b)) {
                break;
            }
            out.println(a);
        }
    }

    private String cutString(String str) {
        int len = str.length();
        if (len <= 1) {
            return str;
        }
        Random r = new Random();
        int randomInt = r.nextInt(len - 1);
        String left = str.substring(0, randomInt + 1);
        String right = str.substring(randomInt + 1, len);
        boolean isSwap = swap(left, right);
        if (isSwap) {
            String temp = left;
            left = right;
            right = temp;
        }
        return cutString(left) + cutString(right);
    }

    private boolean swap(String a, String b) {
        Random r = new Random();
        int randomInt = r.nextInt(100) % 2;
        if (randomInt == 0) {
            return true;
        }
        return false;
    }
}
